package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	counts := make(map[string]int)
	filePath := "res/dup2.txt"
	f, err := os.Open(filePath)
	if err != nil {

		fmt.Fprintf(os.Stderr, "dup2:%v\n", err)
		return
	}
	countLines(f, counts)
	for line, n := range counts {
		if n > 0 {
			fmt.Println(f.Name())
			fmt.Printf("index: %d, line: %s\n", n, line)
		}

	}
}

func countLines(f *os.File, counts map[string]int) {
	input := bufio.NewScanner(f)
	for input.Scan() {
		counts[input.Text()]++
	}
}
